'use strict';

const Controller = require('egg').Controller;

class CommentController extends Controller {
    async getComm() {
        const { ctx } = this;
        const {m_id,pageIndex,pageSize,type}=ctx.request.body
        console.log('123',ctx.request.body)
        let sql=`SELECT * FROM comment WHERE movieid LIKE ${m_id} AND type Like '${type}' LIMIT ${pageIndex},${pageSize}`
        const data=await this.app.mysql.query(sql)
        ctx.body=data
    }
    async addComm(){
        const {ctx}=this;
        const {input,m_id}=ctx.request.body
        const result = await this.app.mysql.insert('comment', { comname:'匿名用户',content:input,movieid:m_id,type:'最新' });
        if(result.affectedRows){
            ctx.body={
                code:200,
                mes:'发送成功'
            }
        }else{
            ctx.body={
                code:300,
                mes:'发送失败'
            }
        }
    }
}

module.exports = CommentController;
